/**
 * @USER: Administrator
 * @DATE: 2024/9/18 下午8:30
 * @VERSION: 1.0.0
 */
public class LC953 {
    public static void main(String[] args) {
        LC953 lc953 = new LC953();
        String[] words = {"word","world","row"};
        String order = "worldabcefghijkmnpqstuvxyz";
        System.out.println(lc953.isAlienSorted(words, order));
    }
    public boolean isAlienSorted(String[] words, String order) {
        for (int i = 1; i < words.length; i++) {
            if (words[i].contains(words[i-1]) ||words[i-1].contains(words[i]) ) {
                if (words[i].length()<words[i-1].length()) return false;
            }else {
                int length = Math.min(words[i].length(), words[i-1].length());
                for (int j = 0; j < length; j++) {
                    if (words[i].charAt(j) != words[i-1].charAt(j)){
                        if(order.indexOf(words[i].charAt(j))<order.indexOf(words[i-1].charAt(j))) {
                            return false;
                        }else {
                            break;
                        }
                    }
                }
            }
        }
        return true;
    }
}
